/**
* Copyright (c) 2016-2100 yunclouds
*/
package com.yunqian.web;

import com.yunqian.common.CurrentUser;
import com.yunqian.jwt.JwtUser;
import com.yunqian.redot.constant.BooleanStatus;
import com.yunqian.redot.domain.CoursesWords;
import com.yunqian.redot.domain.view.CoursesWordsDetails;
import com.yunqian.redot.service.CoursesWordsDetailsService;
import com.yunqian.redot.service.CoursesWordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;


/**
 * Describe: 课程留言控制器
 *
 * @author zsy
 * 2018-09-29 15:54:17
 */
 @RestController
 @RequestMapping("/api/coursesWords")
public class CoursesWordsController {

     @Autowired
     private CoursesWordsService coursesWordsService;
     @Autowired
     private CoursesWordsDetailsService coursesWordsDetailsService;

    /**
     * 精选留言分页
     *
     * @param params
     * @return
     */
    @PostMapping("/pagination")
    public Page<CoursesWordsDetails> pagination(@RequestBody Map<String, Object> params) {
        params.put("_filter_eq_asBrilliant", BooleanStatus.YES.getCode());
        return coursesWordsDetailsService.pagination(params);
    }

    /**
     * 留言
     *
     * @param coursesWords 对象信息
     */
    @PostMapping
    public CoursesWords save(@RequestBody @Valid CoursesWords coursesWords, @CurrentUser JwtUser user) {
        coursesWords.setCustomerId(user.getId());
        coursesWordsService.save(coursesWords);
        return coursesWords;
    }

}
